<template>
  <Modal
    v-model="config"
    width="800"
    class="modal-tips"
    :mask-closable="false"
    draggable
    :sticky="true"
    footer-hide
    :title="title"
    @on-cancel="cancel"
  >
    <div style="padding-bottom: 30px">
      <div ref="scrollArea" class="main-area">
        <table class="table-area">
          <thead>
            <tr>
              <th>
                <div class="line-style" style="justify-content: center;min-width: 48px">序号</div>
              </th>
              <th>
                <div class="line-style">域名</div>
              </th>
              <th>
                <div class="line-style">结果</div>
              </th>
            </tr>
          </thead>
          <tbody>
            <tr
              v-for="(item, index) in listShow"
              :key="item.domainName + index"
              class="lc-f"
            >
              <td>
                <div class="line-style" style="justify-content: center;">
                  <span class="normal-f f-ell-sin" title="">{{
                    index + 1 + (page - 1) * pageSize
                  }}</span>
                </div>
              </td>
              <td>
                <div class="line-style">
                  <span class="normal-f f-ell-sin" :title="item.domainName">{{
                    item.domainName
                  }}</span>
                </div>
              </td>
              <td>
                <div class="line-style">
                  <span
                    v-if="item.status == 1"
                    class="c-o f-wrap"
                    style="font-size: 12px"
                    >成功</span
                  >
                  <span v-else class="c-o f-wrap" style="font-size: 12px">{{
                    item.msg || item.reason
                  }}</span>
                </div>
              </td>
            </tr>
          </tbody>
        </table>
        <div class="flx-row-e-c" style="margin-top: 10px">
          <Page
            :total="listNum"
            :current="page"
            :page-size="pageSize"
            show-elevator
            show-total
            @on-change="pageChange"
          />
        </div>
      </div>
      <div class="flx-row-c-c" style="margin-top: 30px">
        <div
          class="big-button-size user-strong-button"
          style="margin-right: 50px"
          @click="cancel"
        >
          确定
        </div>
      </div>
    </div>
  </Modal>
</template>

<script>
export default {
  props: {
    title: {
      type: String,
      default: "",
    },
    show: {
      type: Boolean,
      default: false,
    },
    sucList: {
      type: Array,
      default: () => [],
    },
  },
  data() {
    return {
      pageSize: 10,
      page: 1,
    };
  },
  computed: {
    config: {
      get() {
        return this.show;
      },
      set(val) {
        this.$emit("update:show", val);
      },
    },
    listShow() {
      if (this.sucList.length < this.page * this.pageSize) {
        if (
          this.page > 1 &&
          this.sucList.length <= (this.page - 1) * this.pageSize
        ) {
          // eslint-disable-next-line vue/no-side-effects-in-computed-properties
          this.page = this.page - 1;
        }
        return this.sucList.slice((this.page - 1) * this.pageSize);
      }
      return this.sucList.slice(
        (this.page - 1) * this.pageSize,
        (this.page - 1) * this.pageSize + this.pageSize
      );
    },
    listNum() {
      return this.sucList.length;
    },
  },
  watch: {
    show: {
      handler(newValue) {
        if (newValue) {
          this.page = 1;
        }
      },
    },
  },
  methods: {
    cancel() {
      this.config = false;
    },
    // 切换页码
    pageChange(page) {
      this.$refs.scrollArea.scrollTop = 0;
      this.page = page;
    },
  },
};
</script>

<style lang="scss" scoped>
.main-area {
  padding: 15px 20px;
  max-height: 420px;
  overflow-y: auto;
}
</style>
